/*
 * Copyright 2009 XueSong Guo.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.webwheel.utils;

import cn.webwheel.Action;
import cn.webwheel.WebContext;
import cn.webwheel.di.Desire;

/**
 * 默认的动作类抽象实现，可通过使用{@link cn.webwheel.utils.DIFilter}注入当前的应用程序上下文。
 */
abstract public class DefaultAction implements Action {

    protected WebContext webContext;

    /**
     * 注入应用程序上下文，通过标记{@link cn.webwheel.di.Desire}注释让{@link cn.webwheel.utils.DIFilter}注入此参数。
     * @param webContext 应用程序上下文
     */
    @Desire
    public void setWebContext(WebContext webContext) {
        this.webContext = webContext;
    }

    /**
     * 通过当前的{@link cn.webwheel.ObjectFactory#getInstanceOf(Class)}方法获得某个类型的实例。
     * @param cls 类型
     * @return 实例
     */
    public <T> T get(Class<T> cls) {
        return webContext.getMain().getInstanceOf(cls);
    }
}
